public class MainActivity extends Activity implements OnClickListener { private String state = "China"; private TextView edit_state; String[] country; private SpinerPopWindow SpinerCountry = null; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 每次创建一个新的Activity都需要把它放到activity链表管理里面,以便释放内存 init(); } public void init() { edit_state = (TextView) findViewById(R.id.edit_state); edit_state.setText(state); setupCountry(); } private void setupCountry() { edit_state.setOnClickListener(this); country = getResources().getStringArray(R.array.spinner_country); SpinerCountry = new SpinerPopWindow(this); SpinerCountry.setSpinnerAdatper(country); SpinerCountry.setItemListener(new IOnItemSelectListener() { @Override public void onItemClick(int pos) { // TODO Auto-generated method stub setCountry(pos); } }); } @Override public void onClick(View view) { switch (view.getId()) { // case R.id.spinner_state_sex: // showSpinWindow(); // break; case R.id.edit_state: showCountry(); break; } } private void setCountry(int pos) { if (pos >= 0 && pos <= country.length) { // CustemObject value = nameList.get(pos); edit_state.setText(country[pos]); state = country[pos]; } } private void showCountry() { // Log.e("", "showSpinWindow"); SpinerCountry.setWidth(edit_state.getWidth()); SpinerCountry.showAsDropDown(edit_state); } }
评论